﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AntDesign.JsInterop;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using OneOf;
using SageKing.Database.Contracts;

namespace SageKing.UI.Blazor.SageKingAntDesign.Contracts;

public abstract class ModalBase<Tmodel> : IModal<Tmodel>
    where Tmodel : ICloneable
{
    public virtual RenderFragment ModalTemplate { get; set; }
    public virtual string TemplateName { get; set; }
    public virtual string TemplateType { get; set; }

    public virtual string TabTitle { get; set; }
    public virtual string ParentName { get; set; }
    public virtual string Title { get; set; } = "新增";
    public virtual OneOf<string, RenderFragment>? OkTitle { get; set; } = "保存";
    public virtual OneOf<string, RenderFragment>? CancelText { get; set; } = "取消";
    public virtual bool Visible { get; set; }
    public virtual bool Loading { get; set; }
    public virtual Tmodel Model { get; set; }
    public virtual Error? Error { get; set; }
    public virtual string MaxBodyHeight { get; set; } = "77vh";
    public virtual string Class { get; set; } = "modelDefault";
    public virtual string Style { get; set; }
    public virtual OneOf<string, double> Width { get; set; } = "50%";
    public virtual bool Draggable { get; set; } = true;
    public virtual bool Centered { get; set; } = true;
    public virtual bool Closable { get; set; } = true;

    public virtual Dictionary<string, object> Properties { get; set; }

    [Parameter]
    public virtual Action StateHasChangedAction { get; set; }

    public virtual Task EditOnStatusSwitch(Tmodel row)
    {
        return Task.FromResult(true);
    }

    public virtual Task HandleClose(MouseEventArgs e)
    {
        Visible = false;
        return Task.FromResult(false);
    }

    public virtual Task HandleOk(MouseEventArgs e)
    {
        return Task.FromResult(true);
    }

    public virtual Task ResizedChanged(HtmlElement e)
    {
        return Task.CompletedTask;
    }
    
}
